/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amuthu.expression.function.indicator;

import org.amuthu.DataStore;
import org.amuthu.expression.Expression;
import org.amuthu.expression.terminal.QuoteExpression;
import org.amuthu.indicator.IndicatorQuoteType;
import org.amuthu.parser.ExpressionVisitor;

/**
 *
 * @author prabhu
 */
public abstract class MaFunction extends BaseIndicatorFunction
{
   private IndicatorQuoteType quoteType;

   public IndicatorQuoteType getMaQuoteType()
   {
      return quoteType;
   }

   public void setMaQuoteType(IndicatorQuoteType quoteType)
   {
      this.quoteType = quoteType;
   }

   @Override
   public boolean doUpdateParameters(DataStore dataStore, Expression[] arguments, ExpressionVisitor visitor)
   {
      if (arguments.length < 2)
      {
         return false;
      }

      quoteType = getIndicatorQuoteType(((QuoteExpression) arguments[0]).getQuoteKind());

      int period = (int) visitor.evaluate(arguments[1]);

      if (period < 0)
      {
         return false;
      }

      int startOffset = (arguments.length > 2) ? (int) visitor.evaluate(arguments[2]) : 0;

      setPeriod(period);
      setOffset(startOffset);

      return true;
   }
}
